<template>
  <div class="trend-root">
    <formTitleVue
      title="预警趋势统计"
      :selectOptions="selectOptions"
    />
    <!-- <div id="echarts-trend"></div> -->
    <myLine domId="warnAnalysis-trend-echarts" height="30vh" :chartsData="chartsData"/>
  </div>
</template>

<script>
  import formTitleVue from "@/components/FormTitle/formTitle.vue";
  import myLine from '@/components/Echarts/myLine.vue';
  import { time_select_optios } from '@/utils/global.js';
  import {alarmList} from "@/api/alarm/statistics";

  export default {
    name: "trend",
    components: {
      formTitleVue,myLine,
    },
    props: {
      alarmTypeOptions: {
        type: Array,
        default: [],
      },
      dateValueMap:{
        type: Object,
        default: {},
      },
      dataSelectOptions:{
        type: Array,
        default: [],
      }
    },
    data() {
      return {
        selectOptions: [
          {
            selectValue: "全部类型",
            options:this.alarmTypeOptions,
            changeFn:this.changeType
          },
          {
            selectValue: 1,
            options:this.dataSelectOptions,
            changeFn:this.changeDate
          },
        ],
        chartsData: {
          xData: ["06", "07", "08", "09", "10"],
          yData: [],
        },
        dateTypeObject:{ "近一月":"03", "近半年":"02", "近一年":"02"},
        searChForm: {
          startTime: '',
          endTime: '',
          type:1,
          dateType:"",
          modeType:""
        },
      };
    },
    methods: {
      changeType(val){
        console.log("changeType：",val)
        this.searChForm.modeType = val
        this.search()
      },
      changeDate(item){
        console.log("changeDate：",item)
        this.searChForm.startTime = this.dateValueMap[item].startTime+ " 00:00:00"
        this.searChForm.endTime = this.dateValueMap[item].endTime+ " 23:59:59"
        this.search()
      },
      search() {
        this.fetch({
          ...this.searChForm,
        })
      },
      fetch(params = {}) {
        params.areaCode = this.$store.state.account.user.deptIds;
        params.dateType = "02"
        alarmList(params).then(res => {
          if (res.code == 200) {
            this.chartsData.xData=res.data.xdata
            this.chartsData.yData=res.data.ydata
          } else {
            this.$message({
              message: this.$t('tips.systemException'),
              type: 'error'
            })
          }
        }).finally(final => {
          console.log("error")
        })
      },
      getData() {
        this.chartsData.yData = [{
          name: '总数',
          data: [150, 230, 224, 218, 135]
        },
          {
            name: '市政设施',
            data: [180, 260, 234, 178, 105]
          },
        ];
      },
    },
    created() {
      this.changeDate(1)
    },
  };
</script>

<style lang="scss" scoped>
  .trend-root {
    #echarts-trend {
      height: 30vh;
    }
  }
</style>
